﻿
namespace GVPSys.sysbase
{
    /// <summary> 验证的Command拦截器 </summary>
    public class ValidationCommandInterceptor : ICommandInterceptor
    {
        private readonly IValidatable validator;
        public const string NotPassValue = "VerificationFailure";

        public ValidationCommandInterceptor(IValidatable validator)
        {
            this.validator = validator;
        }

        object ICommandInterceptor.Invoke(IInvocation invocation)
        {
            if (validator == null)
            {
                return invocation.Proceed();
            }

            return validator.IsPass() ? invocation.Proceed() : NotPassValue;
        }
    }
}
